package lab03.test08;

import java.io.*;

public class Test08 {
    public static void main(String[] args) {
        File myFile = new File("F:\\3.txt");
        try {
            myFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        FileInputStream fileInput = null;

        try {
            fileInputStream = new FileInputStream("F:\\1.txt");    //实例化读取1.txt文件的输入流
            fileInput = new FileInputStream("F:\\2.txt");            //实例化读取2.txt文件的输出流
            fileOutputStream = new FileOutputStream("F:\\3.txt");    //实例化3.txt的输出流

            int ch;
            int c;
            while ((ch = fileInputStream.read()) != -1 | (c = fileInput.read()) != -1) {  //依次交替读取文件直到文件读取完毕
                fileOutputStream.write(ch);
                fileOutputStream.write(c);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();
                fileInput.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}